package v1_road_pool

import (
	"context"

	"kami/internal/consts"
	"kami/internal/dao"
	"kami/internal/model"
	"kami/internal/model/entity"
	"kami/internal/service"
	"kami/utility/config"
)

func init() {
	service.RegisterRoadPool(New())
}

func New() *sRoadPool {
	return &sRoadPool{}
}

type sRoadPool struct{}

func (s *sRoadPool) GetSimpleAll(ctx context.Context) (data []model.RoadPoolSimpleInfo, err error) {
	data = []model.RoadPoolSimpleInfo{}
	m := dao.V1RoadPoolInfo.Ctx(ctx).
		Where(dao.V1RoadPoolInfo.Columns().Status, consts.StatusActive).
		DB(config.GetDatabaseV1())
	err = m.Scan(&data)
	return
}

func (s *sRoadPool) GetDetailByCode(ctx context.Context, code string) (data *entity.V1RoadPoolInfo, err error) {
	data = &entity.V1RoadPoolInfo{}
	err = dao.V1RoadPoolInfo.Ctx(ctx).
		DB(config.GetDatabaseV1()).
		Where(dao.V1RoadPoolInfo.Columns().RoadPoolCode, code).
		Where(dao.V1RoadPoolInfo.Columns().Status, consts.StatusActive).
		Scan(data)
	return
}
