"""
Generated by <Python Project Utils>
Visit the project in http://code.google.com/p/python-project-utils/
"""

import re
import os
from . import Wrapper

class Game(Wrapper):
	@staticmethod
	def create(file_name):
		match = re.search(r'(^.+?) \[(.+?)\].*$', file_name)

		if match:
			name = match.group(1)
			media_id = match.group(2)
		else:
			name = os.path.splitext(file_name)[0]
			media_id = None

		return Game(None, name, media_id, file_name)

	_table = "games"
	_attributes_columns = {}
	_attributes_columns["_id"] = "id"
	_attributes_columns["_name"] = "name"
	_attributes_columns["_file_name"] = "file_name"
	_attributes_columns["_media_id"] = "media_id"

	@classmethod
	def find_by_name(cls, name):
		return cls.find_by_attribute("_name", "'{0}'".format(name.replace("'", "''")))

	@classmethod
	def find_by_media_id(cls, media_id):
		return cls.find_by_attribute("_media_id", media_id)

	@classmethod
	def find_by_file_name(cls, file_name):
		return cls.find_by_attribute("_file_name", "'{0}'".format(file_name.replace("'", "''")))

	def __init__(self, id = None, name = None, media_id = None, file_name = None):
		Wrapper.__init__(self, id)

		self._name = name
		self._media_id = media_id
		self._file_name = file_name

	def get_name(self):
		return self._name

	def get_media_id(self):
		return self._media_id

	def get_file_name(self):
		return self._file_name

	def set_name(self, name):
		self._name = name

	def set_media_id(self, media_id):
		self._media_id = media_id

	def set_file_name(self, file_name):
		self._file_name = file_name
