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) {
    const res = await (this.get('/content/main_body_user/getUserContribute', '用户投稿列表', {
      page, pageSize,
    })) 
    return transformArrayDataModel<GetContentListItem>(GetContentListItem, res.data as any, `用户投稿列表`, true);
  }
  async contribute(data: ContributeItem) {
    return (this.post('/content/content/contribute', '投稿', data));
  }
}

export default new ContributeApi();
