import { DataModel, transformArrayDataModel } from '@imengyu/js-request-transform';
import { CommonContentApi } from '../CommonContent';

export class IndexStats extends DataModel<IndexStats> {
  constructor() {
    super(IndexStats, "内容详情");
    this.setNameMapperCase('Camel', 'Snake');
    this._convertTable = {
      crData: { clientSide: 'forceArray' },
      minnanCr: { clientSide: 'forceArray' },
      historyData: { clientSide: 'forceArray' },
      inheritorData: { clientSide: 'forceArray' },
      ichData: { clientSide: 'forceArray' },
      ichCenter: { clientSide: 'forceArray' },
      villageData: { clientSide: 'forceArray' }
    }
  }

  crData: any;
  minnanCr: any;
  historyData: any;
  inheritorData: any;
  ichData: any;
  ichCenter: any;
  villageData: any;
}
export class IndexBanner extends DataModel<IndexBanner> {
  constructor() {
    super(IndexBanner, "首页轮播");
    this.setNameMapperCase('Camel', 'Snake');
    this._convertTable = {}
  }

  id = '';
  title = '';
  image = '';
  typeText = '';
  sceneText = '';
  openTypeText = '';
  statusText = '';
}
export class IndexTerminalConfig extends DataModel<IndexTerminalConfig> {
  constructor() {
    super(IndexTerminalConfig, "终端按钮配置");
    this.setNameMapperCase('Camel', 'Snake');
    this._convertTable = {}
  }

  id = '';
  name = '';
  images = [] as string[];
  pageJson = [] as {
    title: string,
    logo: string,
    page: string,
  }[];
  inheritorId = 0;
  ichId = 0;
}



export class IndexContentApi extends CommonContentApi {

  constructor() {
    super(undefined, 3, "闽南文化概况", 288);
  }

  async getStats() {
    return (await this.get('/volunteer/statistics/webData', '闽南文化首页数据统计', {
    }, IndexStats)).data as IndexStats
  }
  async getBanner() {
    return transformArrayDataModel<IndexBanner>(
      IndexBanner,
      (await this.get('/content/banner_function/getotherBanner', '首页轮播图列表', {
        open_type: 3,
      })).data as any, 
      '首页轮播图列表'
    );
  }
  async bindMachineCode(userName: string, deviceCode: string) {
    return (await this.post('/resource/site_bind/bind/bindMachineCode', {
      username: userName,
      device_code: deviceCode,
    }, '绑定机器码')).data as any;
  }
  async getTerminalConfig(deviceCode: string) {
    return (await this.get('/resource/site_bind/getInfo/getTerminalConfig', '获取终端按钮配置', {
      device_code: deviceCode,
    }, IndexTerminalConfig)).data as IndexTerminalConfig
  }

}

export default new IndexContentApi();
