import type { Result } from '../domain/Result';
import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';

/**
 * Use Case interface for commands.
 *
 * Use cases represent application-level business logic. They coordinate domain objects and repositories,
 * but contain no infrastructure or framework concerns.
 *
 * Commands change system state and return a Result on execution. If a business rejection is possible,
 * the result contains an ApplicationErrorCode<E>. Use cases do not throw errors; they use error codes in Result.
 *
 * Example:
 * ```typescript
 * export type CreateRaceErrorCode =
 *   | 'INSUFFICIENT_PERMISSIONS'
 *   | 'RACE_ALREADY_EXISTS'
 *   | 'INVALID_RACE_CONFIG';
 *
 * export class CreateRaceUseCase implements UseCase<CreateRaceInput, void, CreateRaceErrorCode> {
 *   execute(input: CreateRaceInput): Promise<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>> {
 *     // implementation
 *   }
 * }
 * ```
 *
 * @template Input - The input type for the use case
 * @template Success - The success type in the Result
 * @template ErrorCode - The error code type for ApplicationErrorCode
 */
export interface UseCase<Input, Success, ErrorCode extends string> {
  execute(input: Input): Promise<Result<Success, ApplicationErrorCode<ErrorCode>>>;
}