<?php
namespace Api\PhpServices\Subscribe;

abstract class Subscribe
{
    /**
     * 错误码
     */
    const ERROR_CODE = [
        1 => '参数有误',
        2 => '订阅失败',
        3 => '请勿重复订阅',
        4 => '取消订阅失败',
        5 => '获取订阅列表失败'
    ];

    /**
     * 成功响应
     * @param null $data
     * @return array|int[]
     */
    protected function success($data = null)
    {
        if (is_null($data)) {
            return ['code' => 0];
        }
        return ['code' => 0, 'data'=>$data];
    }

    /**
     * 异常响应
     * @param $code
     * @return array
     */
    protected function error($code)
    {
        return ["code" => $code, "msg" => self::ERROR_CODE[$code]];
    }

    /**
     * @param int $userid
     * @param string $subscribe_id
     * @param string $name
     * @return array
     */
    abstract protected function add($userid, $subscribe_id);
    /**
     * @param int $userid
     * @param array $subscribe_ids 支持批量
     * @return array
     */
    abstract protected function delete($userid, $subscribe_ids);
    /**
     * @param int $userid
     * @param int $page
     * @param int $page_size
     * @return array
     */
    abstract protected function getList($userid, $page, $page_size = 100);
}
