package v1_road

import (
	"context"

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

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

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

type sRoad struct{}

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

func (s *sRoad) GetDetailByUid(ctx context.Context, uid string) (data *entity.V1RoadInfo, err error) {
	data = &entity.V1RoadInfo{}
	m := dao.V1RoadInfo.Ctx(ctx).DB(config.GetDatabaseV1()).
		Where(dao.V1RoadInfo.Columns().Status, consts.StatusActive).
		Where(dao.V1RoadInfo.Columns().RoadUid, uid)
	err = m.Scan(&data)
	return
}
