<?php
namespace App\Services\demo;

use App\Models\demo\mysql\User;

class MysqlService
{
    public function addUser()
    {
        $user = User::getWriteInstance();
        $data = [
            'name' => 'dw07',
            'mobile' => '17701340007'
        ];
        return $user->add($data);
    }

    public function addManyUser()
    {
        $user = User::getWriteInstance();
        $data = [
            [
                'name' => 'dw08',
                'mobile' => '17701340008'
            ],
            [
                'name' => 'dw09',
                'mobile' => '17701340009'
            ]
        ];
        return $user->addMany($data);
    }

    public function deleteUser()
    {
        $user = User::getWriteInstance();
        $params = [
            'name' => 'dw08'
        ];
        return $user->delete($params);
    }

    public function updateUser()
    {
        $user = User::getWriteInstance();
        $params = [
            'name' =>  'dw02'
        ];
        $data = [
            'mobile' => '15030690002'
        ];
        return $user->update($params, $data);
    }

    public function getUser()
    {
        $user = User::getInstance();
        $params = [
            'name' =>  'dw02'
        ];
        $column = [
            'name',
            'mobile'
        ];
        return $user->get($params, $column);
    }

    public function getManyUser()
    {
        $user = User::getInstance();
        $params = [
            'id[>]' =>  3
        ];
        $column = [
            'name',
            'mobile'
        ];
        return $user->getMany($params, $column);
    }

    public function countUser()
    {
        $user = User::getInstance();
        $params = [
            'master_name' =>  'dw04'
        ];
        $column = 'id';
        return $user->count($params, $column);
    }

    public function maxUser()
    {
        $user = User::getInstance();
        $params = [
            'id[>]' => 1
        ];
        $column = 'id';
        return $user->max($params, $column);
    }

    public function minUser()
    {
        $user = User::getInstance();
        $params = [
            'id[>]' => 1
        ];
        $column = 'id';
        return $user->min($params, $column);
    }

    public function avgUser()
    {
        $user = User::getInstance();
        $params = [
            'id[>]' => 1
        ];
        $column = 'id';
        return $user->avg($params, $column);
    }

    public function sumUser()
    {
        $user = User::getInstance();
        $params = [
            'id[>]' => 1
        ];
        $column = 'id';
        return $user->sum($params, $column);
    }
}
