from google.cloud import storage

class Storage:
    def __init__(self, project_id, bucket_name, credentials=None):
        self.project_id = project_id
        print(self.project_id)
        self.bucket_name = bucket_name
        if credentials:
            self.client = storage.Client(project=self.project_id, credentials=credentials)
        else:
            self.client = storage.Client(project=self.project_id)

    def upload_from_file(self, image_path, file_path):
        bucket = self.client.bucket(self.bucket_name)
        blob = bucket.blob(file_path)

        blob.upload_from_filename(image_path, content_type="image/jpeg")

        # Make the image public
        blob.make_public()
        public_url = blob.public_url
        
        # Return the public URL
        return public_url
    
    def upload_from_byte(self, image_bytes, file_path):
        bucket = self.client.bucket(self.bucket_name)
        blob = bucket.blob(file_path)
        
        blob.upload_from_string(image_bytes, content_type="image/png")
        
        # Make the image public
        blob.make_public()
        public_url = blob.public_url
        
        # Return the public URL
        return public_url