from django.db import models
from django.contrib.auth.models import AbstractUser,User



class User(AbstractUser):
    phone = models.IntegerField(null=True,blank=True)
    address = models.TextField(null=True,blank=True)
    role = models.CharField(max_length=255,null=True,blank=True,default='Customer')
    

class Category(models.Model):
    name = models.CharField(max_length=255)


class station(models.Model):
    name = models.CharField(max_length=255)
    location = models.CharField(max_length=255)  
    map = models.TextField()
    capacity = models.IntegerField()
    

class bike(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE,null=True,blank=True)
    category = models.ForeignKey(Category,on_delete=models.CASCADE,null=True,blank=True)
    station = models.ForeignKey(station,on_delete=models.CASCADE,null=True,blank=True)
    code = models.CharField(max_length=255)
    model=models.TextField(null=True,blank=True)  
    price = models.IntegerField(null=True,blank=True)
    image = models.ImageField(upload_to='bike_image')
    is_available = models.BooleanField(default=True)
    is_running = models.BooleanField(default=False)
    
class rental(models.Model):
    bike = models.ForeignKey(bike,on_delete=models.CASCADE,null=True,blank=True)
    start_time = models.DateTimeField(null=True,blank=True)
    end_time = models.DateTimeField(null=True, blank=True)
    rental_cost = models.DecimalField(max_digits=10,decimal_places=2)
    is_returned = models.BooleanField()

class payment(models.Model):
    rental = models.IntegerField(null=True,blank=True)
    method = models.CharField(max_length=100)
    status = models.BooleanField()

class Feedback(models.Model):
    name = models.CharField(max_length=255) 
    email = models.EmailField(null=True,blank=True)
    message = models.CharField(max_length=255) 

class Enquiry(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField()
    subject = models.CharField(max_length=200)
    message = models.TextField()

    def __str__(self):
        return f"{self.name} - {self.subject}"

