package company

import (
	"bordrobot/lib/run"
)

type Company struct {
	Id           int    `db:"id"`
	Name         string `db:"name"`
	MemberNumber string `db:"member_number"`
	Username     string `db:"username"`
	Password     string `db:"password"`
}
type CompanyInfo struct {
	Company Company
	Month   float64
	Year    float64
}

func (c *Company) Create() error {
	sq := `
insert into company (name, member_number, username, password) 
VALUES (:name, :member_number, :username, :password)
`
	_, err := run.DB.NamedExec(sq, &c)
	return err
}
func (c *Company) Edit() error {
	sq := `
	UPDATE company SET 
		name = :name, 
    	member_number = :member_number, 
    	username = :username, 
    	password = :password
	WHERE id = :id;`
	_, err := run.DB.NamedExec(sq, &c)
	return err
}

//func GetCompany(companyName string) (Company, error) {
//	sq := `
//		SELECT * FROM company WHERE company = ?
//	`
//	err := run.DB.Get(&Company, sq, companyName)
//	if err != nil {
//		return Company{}, err
//	}
//	return Company{}, nil
//}
//

func GetCompany(companyID float64) (Company, error) {
	var company Company

	sq := `
		SELECT * FROM company WHERE id = ?
	`
	err := run.DB.Get(&company, sq, companyID)
	if err != nil {
		return Company{}, err
	}

	return company, nil
}
