package repository

import (
	"bpmsapi/entity"

	"github.com/jmoiron/sqlx"
)

type AddressActions interface {
	AddAddress(input entity.AddAddressInput) (int, error)
}

type AddressRepository struct {
	db *sqlx.DB
}

// auth-jwt
func AddressRepositoryInit(db *sqlx.DB) *AddressRepository {
	return &AddressRepository{
		db: db,
	}
}

func (addressRepo *AddressRepository) AddAddress(input entity.AddAddressInput) (int, error) {
	query := "INSERT INTO `BPMS_ADDRESS`(`Country`, `State`, `City`, `Area_Name`, `Address_Line1`, `Address_Line2`, `Pincode`) VALUES ('India', :State, :City, :Area_Name, :Address_Line1, :Address_Line2, :Pincode)"
	res, err := addressRepo.db.NamedExec(query, input)
	if err != nil {
		return 0, err
	} else {
		addressID, _ := res.LastInsertId()
		return int(addressID), nil
	}
}
