package main

import (
	"fmt"
	"log"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func CreateStockRequestsTable() {
	dsn := "host=66.116.207.225 user=admin password=Package@123# dbname=nearledb port=5433 sslmode=disable TimeZone=Asia/Kolkata"
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		log.Fatalf("failed to connect database: %v", err)
	}

	query := `CREATE TABLE IF NOT EXISTS stockrequests (
		requestid SERIAL PRIMARY KEY,
		tenantid INT NOT NULL,
		locationid INT NOT NULL,
		productid INT NOT NULL,
		qty INT NOT NULL,
		status VARCHAR(50) DEFAULT 'Pending',
		created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
		updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
	);`

	if err := db.Exec(query).Error; err != nil {
		log.Fatalf("failed to create table: %v", err)
	}
	fmt.Println("Table stockrequests created successfully")
}
