import type { ConditionValue } from '@/js/conditions';
import type { Layout, Properties } from '@/js/kintone-rest-api-client';
import type { DropdownItem } from 'kintone-ui-component';

export interface FieldsJoinMapping {
  leftField: string;
  rightField: string;
}

export interface WhereCondition {
  field: string;
  condition: ConditionValue;
  data: string;
}

export interface JoinTable {
  id: number;    // 用于唯一区分
  app: string;   // 取得元アプリ
  table: string; // テーブル
  onConditions: FieldsJoinMapping[];  // 連結条件
  fieldsMapping: FieldsJoinMapping[]; // 取得フィールド
  whereConditions: WhereCondition[];  // 絞込条件
}

// 存储的数据格式
export interface SavedData {
  buttonName: string;
  joinTables: JoinTable[];
}

export interface FieldsInfo {
  fields: Properties;
  layout: Layout;
}

export interface CachedData {
  apps: DropdownItem[],
  currentAppFields: FieldsInfo,
}

export interface CachedSelectedAppData {
  appFields: FieldsInfo,
  loading: boolean,
  table: JoinTable,
}
