package company

import (
	"bordrobot/lib/run"
)

type Company struct {
	Name         string `db:"name"`
	MemberNumber string `db:"member_number"`
	Username     string `db:"username"`
	Password     string `db:"password"`
}

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 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(companyName string) (Company, error) {
	var company Company

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

	return company, nil
}
