package work import ( "context" "errors" "tercul/internal/domain" ) // Analyzer defines the interface for work analysis operations. type Analyzer interface { AnalyzeWork(ctx context.Context, workID uint) error } // WorkCommands contains the command handlers for the work aggregate. type WorkCommands struct { repo domain.WorkRepository analyzer Analyzer } // NewWorkCommands creates a new WorkCommands handler. func NewWorkCommands(repo domain.WorkRepository, analyzer Analyzer) *WorkCommands { return &WorkCommands{ repo: repo, analyzer: analyzer, } } // CreateWork creates a new work. func (c *WorkCommands) CreateWork(ctx context.Context, work *domain.Work) error { if work == nil { return errors.New("work cannot be nil") } if work.Title == "" { return errors.New("work title cannot be empty") } if work.Language == "" { return errors.New("work language cannot be empty") } return c.repo.Create(ctx, work) } // UpdateWork updates an existing work. func (c *WorkCommands) UpdateWork(ctx context.Context, work *domain.Work) error { if work == nil { return errors.New("work cannot be nil") } if work.ID == 0 { return errors.New("work ID cannot be zero") } if work.Title == "" { return errors.New("work title cannot be empty") } if work.Language == "" { return errors.New("work language cannot be empty") } return c.repo.Update(ctx, work) } // DeleteWork deletes a work by ID. func (c *WorkCommands) DeleteWork(ctx context.Context, id uint) error { if id == 0 { return errors.New("invalid work ID") } return c.repo.Delete(ctx, id) } // AnalyzeWork performs linguistic analysis on a work. func (c *WorkCommands) AnalyzeWork(ctx context.Context, workID uint) error { if workID == 0 { return errors.New("invalid work ID") } return c.analyzer.AnalyzeWork(ctx, workID) }