from django.shortcuts import render, reverse, redirect
from django.urls import reverse_lazy
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.forms import PasswordChangeForm

from .models import User
from .forms import AccountUpdateForm


class AccountListView(LoginRequiredMixin, ListView):
    model = User
    template_name = 'accounts/account_list.html'

class AccountDetailView(LoginRequiredMixin, DetailView):
    model = User
    template_name = 'accounts/account_detail.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        return context

class AccountUpdateView(LoginRequiredMixin, UpdateView):
    model = User
    form_class = AccountUpdateForm
    template_name = 'accounts/account_form.html'

    def get_success_url(self):
        pk = self.kwargs["pk"]
        return reverse('account-detail', kwargs={'pk': pk})

class AccountDeleteView(LoginRequiredMixin, DeleteView):
    model = User
    success_url = reverse_lazy('account-list')
