import { Controller } from 'egg';

export default class ActivityController extends Controller {

    public async getActivityList() {
        const { ctx } = this;
        const { page, pageSize, type, groupId, current, activityId, sortField, sortOrder } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityList(page, pageSize, sortField, sortOrder, type, groupId, current, activityId);
        return
    }

    public async updateActivity() {
        const { ctx } = this;
        const { activityId, groupId, beginTime, endTime, type, data } = ctx.request.body;
        let checkActivity = await ctx.service.activity.checkActivityEditable(activityId);
        if(checkActivity) return ctx.body = checkActivity;
        return ctx.body = await ctx.service.activity.updateActivity(activityId, groupId, beginTime, endTime, type, data);
    }

    public async deleteActivity() {
        const { ctx } = this;
        const { activityId } = ctx.request.body;
        let checkActivity = await ctx.service.activity.checkActivityEditable(activityId);
        if(checkActivity) return ctx.body = checkActivity;
        ctx.body = await ctx.service.activity.deleteActivity(activityId);

    }

    public async getActivityGroupList() {
        const { ctx } = this;
        const { page, pageSize, serverId, current, groupId } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityGroupList(page, pageSize, serverId, current, groupId);
        return
    }

    public async getActivityGroupTypeList() {
        const { ctx } = this;
        const { page, pageSize, sortField, sortOrder, groupType, groupTypeName } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityGroupTypeList(page, pageSize, sortField, sortOrder, groupType, groupTypeName);
        return
    }

    public async updateActivityGroupType() {
        const { ctx } = this;
        const { groupType, groupTypeName, activityTypes } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityGroupType(groupType, groupTypeName, activityTypes);
        return
    }

    public async deleteActivityGroupType() {
        const { ctx } = this;
        const { groupType } = ctx.request.body;
        ctx.body = await ctx.service.activity.deleteActivityGroupType(groupType);
        return
    }

    public async saveGroupTypeToActivityGroup() {
        const { ctx } = this;
        const { groupId, groupType } = ctx.request.body;
        ctx.body = await ctx.service.activity.saveGroupTypeToActivityGroup(groupId, groupType);
        return
    }

    public async getGroupDataById() {
        const { ctx } = this;
        const { groupId } = ctx.request.body;
        ctx.body = await ctx.service.activity.getGroupDataById(groupId);
        return
    }
    
    public async updateActivityGroupName() {
        const { ctx } = this;
        const { groupId, groupName } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityGroupName(groupId, groupName);
        return
    }

    public async saveActivitiesToGroup() {
        const { ctx } = this;
        const { groupId, activities } = ctx.request.body;
        ctx.body = await ctx.service.activity.saveActivitiesToGroup(groupId, activities);
        return
    }

    public async saveSingleActivityToGroup() {
        const { ctx } = this;
        const { groupId, index, activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.saveSingleActivityToGroup(groupId, index, activityId);
        return
    }

    public async saveGroupToServer() {
        const { ctx } = this;
        const { groupId, serverIds } = ctx.request.body;
        ctx.body = await ctx.service.activity.saveGroupToServer(groupId, serverIds);
        return
    }

    public async createGroup() {
        const { ctx } = this;
        ctx.body = await ctx.service.activity.createGroup();
        return
    }

    public async deleteGroup() {
        const { ctx } = this;
        const { groupId } = ctx.request.body;
        ctx.body = await ctx.service.activity.deleteGroup(groupId);
        return
    }
    
    public async getActivityTaskPoint() {
        const { ctx } = this;
        const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
        ctx.body = await ctx.service.activity.getActivityTaskPoint(page, pageSize, sortField, sortOrder, form);
        return
    }

    public async createTaskToActivity() {
        const { ctx } = this;
        const { taskType, activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.createTaskToActivity(taskType, activityId);
        return
    }

    public async updateActivityTaskPoint() {
        const { ctx } = this;
        const { taskType, taskId, activityId, point } = ctx.request.body;
        ctx.body = await ctx.service.activity.updateActivityTaskPoint(taskType, taskId, activityId, point);
        return
    }

    public async delActivityTaskPoint() {
        const { ctx } = this;
        const { taskType, taskId, activityId } = ctx.request.body;
        ctx.body = await ctx.service.activity.delActivityTaskPoint(taskType, taskId, activityId);
        return
    }
    
}
