package biz

import (
	"context"
	"time"
)

type Position struct {
	ID        uint
	CreatedAt time.Time
	UpdatedAt time.Time
	Name      string
	Code      string
	Sort      int
	Status    *bool
	Remark    string
}

type PositionListFilter struct {
	Name   string
	Code   string
	Status *bool
}

type PositionRepo interface {
	CreatePosition(context.Context, *Position) error
	UpdatePosition(context.Context, *Position) error
	DeletePosition(context.Context, uint) error
	FindPosition(context.Context, uint) (*Position, error)
	ListPositions(context.Context, int, int, *PositionListFilter) ([]*Position, int64, error)
	PositionUserIDs(context.Context, uint) ([]uint, error)
	SetPositionUsers(context.Context, uint, []uint) error
	SetUserPositions(context.Context, uint, []uint) error
}

type PositionUsecase struct{ PositionRepo }

func NewPositionUsecase(repo PositionRepo) *PositionUsecase {
	return &PositionUsecase{PositionRepo: repo}
}

func (uc *PositionUsecase) Positions(ctx context.Context, page, size int, filter *PositionListFilter) ([]*Position, int64, error) {
	return uc.ListPositions(ctx, page, size, filter)
}

func (uc *PositionUsecase) Position(ctx context.Context, id uint) (*Position, error) {
	return uc.FindPosition(ctx, id)
}
