package mysqlkindboxreq

import (
	"database/sql"

	"git.gocasts.ir/ebhomengo/niki/entity"
	"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)

func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) {
	var kindBoxReq entity.KindBoxReq
	var kindBoxStatus string
	var kindBoxType string
	var countAccept sql.NullInt64
	var desc sql.NullString
	err := scanner.Scan(&kindBoxReq.ID, &kindBoxReq.BenefactorID, &kindBoxType, &kindBoxReq.AddressID, &kindBoxReq.CountRequested, &countAccept,
		&desc,
		&kindBoxReq.ReferDate, &kindBoxStatus, &kindBoxReq.CreatedAt)

	if countAccept.Valid {
		kindBoxReq.CountAccepted = uint(countAccept.Int64)
	}
	if desc.Valid {
		kindBoxReq.Description = desc.String
	}
	kindBoxReq.Status = entity.MapToKindBoxReqStatus(kindBoxStatus)
	kindBoxReq.KindBoxType = entity.MapToKindBoxType(kindBoxType)

	return kindBoxReq, err
}
