from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models
from django_ckeditor_5.fields import CKEditor5Field

from storages.backends.gcloud import GoogleCloudStorage

storage = GoogleCloudStorage()

CUSTOM_DOMAIN_PREFIX ='https://benotx.beauty/'
class Upload:
    @staticmethod
    def upload_image(file, filename):
        try:

            target_path = '/images/' + filename
            path = storage.save(target_path, file)
            file_url=CUSTOM_DOMAIN_PREFIX+target_path
            print(file_url)
            return file_url
          #  return storage.url(path)
        except Exception as e:
            target_path = '/images/' + filename
            file_url = CUSTOM_DOMAIN_PREFIX + target_path
            print(file_url)
            print(e)
            print("Failed to upload!")
            return file_url


# Create your models here.


class Post(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=500)
    feature_video = models.CharField(max_length=500)
    feature_photo = models.CharField(max_length=500)
    short_description = models.CharField(max_length=500)
    description = CKEditor5Field('Text', config_name='extends')


class Project(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=500)
    feature_video = models.CharField(max_length=500)
    feature_photo = models.CharField(max_length=500)
    short_description = models.CharField(max_length=500)
    description = models.TextField()


class ContentStaticPages(models.Model):
    profile = models.TextField()
    about = models.TextField()
    privacy_policy = models.TextField()
