package system

import (
	"context"
	"time"
)

type Department struct {
	ID        uint
	CreatedAt time.Time
	UpdatedAt time.Time
	Name      string
	ParentID  uint
	Ancestors string
	Sort      int
	LeaderID  uint
	Leader    *User
	Status    *bool
	Children  []*Department
	NamePath  string
}

type DepartmentRepo interface {
	CreateDepartment(context.Context, *Department) error
	UpdateDepartment(context.Context, *Department) error
	DeleteDepartment(context.Context, uint) error
	FindDepartment(context.Context, uint) (*Department, error)
	ListDepartments(context.Context, string) ([]*Department, error)
	DepartmentUserIDs(context.Context, uint) ([]uint, error)
	SetDepartmentUsers(context.Context, uint, []uint) error
	SetUserDepartments(context.Context, uint, []uint, uint) error
}

type DepartmentUsecase struct{ DepartmentRepo }

func NewDepartmentUsecase(repo DepartmentRepo) *DepartmentUsecase {
	return &DepartmentUsecase{DepartmentRepo: repo}
}

func (uc *DepartmentUsecase) Departments(ctx context.Context, name string) ([]*Department, error) {
	return uc.ListDepartments(ctx, name)
}

func (uc *DepartmentUsecase) Department(ctx context.Context, id uint) (*Department, error) {
	return uc.FindDepartment(ctx, id)
}
