<?php

use App\Company;
use App\Pricing;
use App\Repositories\CompanyRepository;
use App\Role;
use App\UserSubscription;
use App\User;
use Carbon\Carbon;
use Illuminate\Database\Seeder;

class SuperAdminUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        /**
         * SUPERADMIN
         */
        $superadmin_user = factory(App\User::class)->create([
            "name" => "Bisual",
            "surnames" => "Administrators",
            "phone" => "34 678 123 345",
            "email" => "admin@bisual.net",
            "password" => "12345"
        ]);

        $user_subscription = new UserSubscription();
        $user_subscription->user_id = $superadmin_user->id;
        $user_subscription->role_id = Role::where("slug", "super_admin")->first()->id; //sempre sera superadmin
        $user_subscription->pricing_id = null;
        $user_subscription->start_date = Carbon::today();
        $user_subscription->end_date = Carbon::today()->addMonths(10);
        $user_subscription->renew = 1;
        $user_subscription->save();


        /**
         * COMPANY ADMIN
         */

        $company_admin = factory(App\User::class)->create([
            "name" => "Pepito",
            "surnames" => "Palotes",
            "phone" => "34 678 123 345",
            "email" => "company@admin.com",
            "password" => "12345"
        ]);

        $pricing = Pricing::all()->random();
        $user_subscription = new UserSubscription();
        $user_subscription->user_id = $company_admin->id;
        $user_subscription->role_id = Role::where("slug", "company_admin")->first()->id; //sempre sera superadmin
        $user_subscription->pricing_id = $pricing->id;
        $user_subscription->wod_counter = $pricing->wod_counter;
        $user_subscription->open_counter = $pricing->open_counter;
        $user_subscription->total_counter = $pricing->total_counter;
        $user_subscription->start_date = Carbon::today();
        $user_subscription->end_date = Carbon::today()->addMonths(10);
        $user_subscription->renew = 1;
        $user_subscription->save();


        /**
         * BOX ADMIN
         */
        $box_admin = factory(App\User::class)->create([
            "name" => "Pepito",
            "surnames" => "Palotes",
            "phone" => "34 678 123 345",
            "email" => "box@admin.com",
            "password" => "12345"
        ]);

        $pricing = Pricing::all()->random();
        $user_subscription = new UserSubscription();
        $user_subscription->user_id = $box_admin->id;
        $user_subscription->role_id = Role::where("slug", "box_admin")->first()->id; //sempre sera superadmin
        $user_subscription->pricing_id = $pricing->id;
        $user_subscription->wod_counter = $pricing->wod_counter;
        $user_subscription->open_counter = $pricing->open_counter;
        $user_subscription->total_counter = $pricing->total_counter;
        $user_subscription->start_date = Carbon::today();
        $user_subscription->end_date = Carbon::today()->addMonths(10);
        $user_subscription->renew = 1;
        $user_subscription->save();


        /**
         * COACH
         */
        $coach = factory(App\User::class)->create([
            "name" => "Pepito",
            "surnames" => "Palotes",
            "phone" => "34 678 123 345",
            "email" => "coach@admin.com",
            "password" => "12345"
        ]);


        $pricing = Pricing::all()->random();
        $user_subscription = new UserSubscription();
        $user_subscription->user_id = $coach->id;
        $user_subscription->role_id = Role::where("slug", "coach")->first()->id; //sempre sera superadmin
        $user_subscription->pricing_id = $pricing->id;
        $user_subscription->wod_counter = $pricing->wod_counter;
        $user_subscription->open_counter = $pricing->open_counter;
        $user_subscription->total_counter = $pricing->total_counter;
        $user_subscription->start_date = Carbon::today();
        $user_subscription->end_date = Carbon::today()->addMonths(10);
        $user_subscription->renew = 1;
        $user_subscription->save();



        /**
         * ATHLETE
         */
        $athlete = factory(App\User::class)->create([
            "name" => "Pepito",
            "surnames" => "Palotes",
            "phone" => "34 678 123 345",
            "email" => "athlete@admin.com",
            "password" => "12345"
        ]);

        $pricing = Pricing::all()->random();
        $user_subscription = new UserSubscription();
        $user_subscription->user_id = $athlete->id;
        $user_subscription->role_id = Role::where("slug", "athlete")->first()->id; //sempre sera superadmin
        $user_subscription->pricing_id = $pricing->id;
        $user_subscription->wod_counter = $pricing->wod_counter;
        $user_subscription->open_counter = $pricing->open_counter;
        $user_subscription->total_counter = $pricing->total_counter;
        $user_subscription->start_date = Carbon::today();
        $user_subscription->end_date = Carbon::today()->addMonths(10);
        $user_subscription->renew = 1;
        $user_subscription->save();
    }
}
