package service import ( "context" "database/sql" "fmt" "boc/repository" ) // LegalService handles business logic for legal operations type LegalService struct { repo *repository.LegalRepository db *sql.DB } func NewLegalService(db *sql.DB) *LegalService { return &LegalService{ repo: repository.NewLegalRepository(db), db: db, } } // ListContracts returns all contracts func (s *LegalService) ListContracts(ctx context.Context) ([]repository.Contract, error) { return s.repo.ListContracts(ctx) } // GetContract returns a single contract by ID func (s *LegalService) GetContract(ctx context.Context, id string) (*repository.Contract, error) { return s.repo.GetContract(ctx, id) } // CreateContract creates a new contract with validation func (s *LegalService) CreateContract(ctx context.Context, c *repository.Contract) error { if c.Title == "" { return fmt.Errorf("contract title is required") } if c.Type == "" { return fmt.Errorf("contract type is required") } if c.CustomerID == "" { return fmt.Errorf("customer ID is required") } if c.Status == "" { c.Status = "draft" } if c.Currency == "" { c.Currency = "USD" } return s.repo.CreateContract(ctx, c) } // UpdateContract updates an existing contract func (s *LegalService) UpdateContract(ctx context.Context, id string, c *repository.Contract) error { if c.Title == "" { return fmt.Errorf("contract title is required") } return s.repo.UpdateContract(ctx, id, c) } // ListTemplates returns all contract templates func (s *LegalService) ListTemplates(ctx context.Context) ([]repository.ContractTemplate, error) { return s.repo.ListTemplates(ctx) } // GetTemplate returns a single template by type func (s *LegalService) GetTemplate(ctx context.Context, contractType string) (*repository.ContractTemplate, error) { return s.repo.GetTemplate(ctx, contractType) }