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<FieldType = string> {
  id: string;
  leftField: FieldType;
  rightField: FieldType;
}

export interface WhereCondition<FieldType = string> {
  id: string;
  field: FieldType;
  condition: ConditionValue;
  data: StringValue;
}

export interface JoinTable<FieldType = string> {
  id: string;
  app: string;   // 取得元アプリ
  table: string; // テーブル
  onConditions: FieldsJoinMapping<FieldType>[];  // 連結条件
  fieldsMapping: FieldsJoinMapping<FieldType>[]; // 取得フィールド
  whereConditions: WhereCondition<FieldType>[];  // 絞込条件
  meta?: Properties;
}

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

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

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

export interface CachedSelectedAppData {
  appFields: FieldsInfo,
  loading: boolean,
  table: JoinTable,
}
export type Record = {
  [fieldCode: string]: Field;
};

export type RecordForParameter = {
  [fieldCode: string]: {
      value: unknown;
  };
};

export type Field={
  type:string;
  value:any;
}

export type FieldLayout={
  type:string;
  code:string;
}

export type StringValue = string | string[];