/**
 * 대시보드 관련 타입 정의
 */

export interface DashboardElement {
  id: string;
  type: "chart" | "widget";
  subtype: "bar" | "pie" | "line" | "exchange" | "weather";
  position: {
    x: number;
    y: number;
  };
  size: {
    width: number;
    height: number;
  };
  title: string;
  customTitle?: string; // 사용자 정의 제목 (옵션)
  showHeader?: boolean; // 헤더 표시 여부 (기본값: true)
  content?: string;
  dataSource?: {
    type: "api" | "database" | "static";
    endpoint?: string;
    query?: string;
    refreshInterval?: number;
    filters?: any[];
    lastExecuted?: string;
  };
  chartConfig?: {
    xAxis?: string;
    yAxis?: string;
    groupBy?: string;
    aggregation?: "sum" | "avg" | "count" | "max" | "min";
    colors?: string[];
    title?: string;
    showLegend?: boolean;
  };
  listConfig?: {
    columns?: any[];
    pagination?: any;
    viewMode?: string;
    cardColumns?: number;
  };
  yardConfig?: {
    layoutId: number;
    layoutName?: string;
  };
  customMetricConfig?: {
    metrics: Array<{
      id: string;
      field: string;
      label: string;
      aggregation: "count" | "sum" | "avg" | "min" | "max";
      unit: string;
      color: "indigo" | "green" | "blue" | "purple" | "orange" | "gray";
      decimals: number;
    }>;
  };
}

export interface Dashboard {
  id: string;
  title: string;
  description?: string;
  thumbnailUrl?: string;
  isPublic: boolean;
  createdBy: string;
  createdAt: string;
  updatedAt: string;
  deletedAt?: string;
  tags?: string[];
  category?: string;
  viewCount: number;
  settings?: {
    resolution?: string;
    backgroundColor?: string;
  };
  elements: DashboardElement[];
}

export interface CreateDashboardRequest {
  title: string;
  description?: string;
  isPublic?: boolean;
  elements: DashboardElement[];
  tags?: string[];
  category?: string;
  settings?: {
    resolution?: string;
    backgroundColor?: string;
  };
}

export interface UpdateDashboardRequest {
  title?: string;
  description?: string;
  isPublic?: boolean;
  elements?: DashboardElement[];
  tags?: string[];
  category?: string;
  settings?: {
    resolution?: string;
    backgroundColor?: string;
  };
}

export interface DashboardListQuery {
  page?: number;
  limit?: number;
  search?: string;
  category?: string;
  isPublic?: boolean;
  createdBy?: string;
}

export interface DashboardShare {
  id: string;
  dashboardId: string;
  sharedWithUser?: string;
  sharedWithRole?: string;
  permissionLevel: "view" | "edit" | "admin";
  createdBy: string;
  createdAt: string;
  expiresAt?: string;
}
