<?php

namespace stripe\endpoints;

use Exception;
use Stripe\Collection;
use Stripe\Customer;
use Stripe\Exception\ApiErrorException;
use traits\stripe_endpoint_t;

class stripe_endpoint_customers
{
    use stripe_endpoint_t;

    /**
     * Create a new customer
     * @param array $data
     * @return Customer
     * @throws ApiErrorException
     * @throws Exception
     */
    public function create(string $email): Customer
    {
        return self::getClient()->customers->create([
            'email' => $email
        ]);
    }

    /**
     * Retrieve a customer
     * @param string $id
     * @return Customer
     * @throws ApiErrorException
     * @throws Exception
     */
    public function retrieve(string $id): Customer
    {
        return self::getClient()->customers->retrieve($id);
    }

    /**
     * Update a customer
     * @param string $id
     * @param array $data
     * @return Customer
     * @throws ApiErrorException
     * @throws Exception
     */
    public function update(string $id, array $data): Customer
    {
        return self::getClient()->customers->update($id, $data);
    }

    /**
     * Delete a customer
     * @param string $id
     * @return Customer
     * @throws Exception
     */
    public function delete(string $id): Customer
    {
        return self::getClient()->customers->delete($id);
    }

    /**
     * List all customers
     * @return Collection
     * @throws ApiErrorException
     * @throws Exception
     */
    public function list(): Collection
    {
        return self::getClient()->customers->all();
    }

}