/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionUserBind;
import com.yami.shop.distribution.comment.param.RangeTimeParam;
import com.yami.shop.distribution.comment.service.DistributionUserBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionUserBind")
public class DistributionUserBindController {

    @Autowired
    private DistributionUserBindService distributionUserBindService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBind:page')")
    public ResponseEntity<IPage<DistributionUserBind>> page(DistributionUserBind distributionUserBind, PageParam<DistributionUserBind> page, RangeTimeParam bindTime, RangeTimeParam invalidTime, String userName, String parentName
    ) {
        IPage<DistributionUserBind> list = distributionUserBindService.distributionMsgsAndUserPage(page, distributionUserBind, bindTime, invalidTime, userName, parentName);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBind:info')")
    public ResponseEntity<DistributionUserBind> info(@PathVariable("id") Long id) {
        DistributionUserBind distributionUserBind = distributionUserBindService.getById(id);
        return ResponseEntity.ok(distributionUserBind);
    }

    /**
     * 保存
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBind:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid DistributionUserBind distributionUserBind) {
        distributionUserBindService.save(distributionUserBind);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBind:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionUserBind distributionUserBind) {
        distributionUserBindService.updateById(distributionUserBind);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBind:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionUserBindService.removeById(id);
        return ResponseEntity.ok().build();
    }
}
