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

export class ContributeItem extends DataModel<ContributeItem> {
  constructor() {
    super(ContributeItem, "投稿");
    this.setNameMapperCase('Camel', 'Snake');
    this._convertTable = {
      id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
    }
    this._nameMapperServer = {
    };
  }
  modelId = 0;
  mainBodyColumnId = 0;
  title = '';
  type = 1;	//内容类型 ：1=文章，2=音频，3=视频，4=相册
  content = '';
}

export class ContributeApi extends AppServerRequestModule<DataModel> {

  constructor() {
    super();
  }

  async getContributeList(page: number, pageSize: number) {
    return (this.get('/content/main_body_user/getUserContribute', '用户投稿列表', {
      page, pageSize,
    })) 
      .then(res => transformArrayDataModel<GetContentListItem>(GetContentListItem, res.data2, `用户投稿列表`, true))
      .catch(e => { throw e });
  }
  async contribute(data: ContributeItem) {
    return (this.post('/content/content/contribute', data, '投稿'));
  }
}

export default new ContributeApi();
