#################################################################################
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Dmitry Sovetov
#
# https://github.com/dmsovetov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################################

import os

from Resource    import Resource
from ...Template import Template

# class FileReference
class FileReference( Resource ):
	# ctor
	def __init__( self, type, path, dir ):
		Resource.__init__( self, 'PBXFileReference', os.path.basename( path ) )
		self.type = type
		self.path = path
		self.dir  = dir

		# static library - archive.ar

	# compile
	def compile( self ):
		return Template( FileReference.Root ).compile( { 'id': self.id, 'isa': self.isa, 'name': self.name, 'type': self.type, 'path': self.path, 'dir': self.dir } )

	# Root
	Root = "\t\t{id} /* {name} */ = {isa = {isa}; explicitFileType = {type}; includeInIndex = 0; name = {name}; path = {path}; sourceTree = {dir}; };\n"

# class BuildFile
class BuildFile( Resource ):
	# ctor
	def __init__( self, owner, file ):
		Resource.__init__( self, 'PBXBuildFile', file.name )
		self.file  = file
		self.owner = owner

	# compile
	def compile( self ):
		return Template( BuildFile.Root ).compile( { 'id': self.id, 'isa': self.isa, 'owner': self.owner.name, 'file.name': self.file.name, 'file.reference': self.file.id } )

	# Root
	Root = "\t\t{id} /* {file.name} in {owner} */ = {isa = {isa}; fileRef = {file.reference} /* {file.name} */; };\n"