/**
 * Rules Engine Type Definitions
 * Based on CLQMS API Specification - Refactored Rule System
 */

export type RuleEventCode = 'ORDER_CREATED';
export type RuleActionType = 'SET_RESULT';

export interface RuleDef {
  RuleID: number;
  RuleCode: string;
  RuleName: string;
  Description?: string;
  EventCode: RuleEventCode | string;
  ConditionExpr?: string | null;
  ConditionExprCompiled?: string | null;
  Priority?: number;
  Active: 0 | 1 | number;
  /** ISO timestamp strings */
  createdAt?: string;
  updatedAt?: string;
  deletedAt?: string | null;
}

export interface RuleAction {
  RuleActionID: number;
  RuleID: number;
  Seq: number;
  ActionType: RuleActionType | string;
  ActionParams: string | Record<string, any>;
  /** ISO timestamp strings */
  createdAt?: string;
  updatedAt?: string;
}

export interface ApiResponse<T> {
  status: 'success' | 'created' | 'error' | string;
  message: string;
  data: T;
}

export interface RulesListResponse extends ApiResponse<RuleDef[]> {}
export interface RuleDetailResponse extends ApiResponse<RuleDef> {}

export interface ValidateExprResponse extends ApiResponse<{ valid: boolean; result?: any; error?: string }> {}

export interface CompileExprResponse {
  compiled: any;
  conditionExprCompiled: string;
}

export type SetResultActionParams = {
  testSiteID?: number;
  testSiteCode?: string;
  value?: any;
  valueExpr?: string;
};
